# -*- coding:utf-8 -*-
# @Time : 2021/10/25 14:54
# @Author : zvs
# @File : sitka_highs
# @Project : untitled
import csv

import matplotlib.pyplot as plt
from datetime import datetime

filename = r'D:\综合实验\ituring\源代码文件\源代码文件\chapter_16\the_csv_file_format' \
           '\data\sitka_weather_2018_simple.csv'
with open(filename) as f:
    reader = csv.reader(f)
    header_row = next(reader)

    # for index, column_header in enumerate(header_row):
    #     print(index, column_header)#指出每个文件头的索引

    #从文件中获取最高温度和日期
    dates, highs, lows = [], [], []
    for row in reader:
        current_date = datetime.strptime(row[2], '%Y-%m-%d')
        high = int(row[5])
        low = int(row[6])
        dates.append(current_date)
        highs.append(high)
        lows.append(low)

#根据最高气温绘制图形
plt.style.use('seaborn')

plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号

fig, ax = plt.subplots()
ax.plot(dates,highs, c='red', alpha=0.5)
ax.plot(dates,lows, c='blue', alpha=0.5)
ax.fill_between(dates, highs, lows, facecolor='blue', alpha=0.1)

#设置图形格式
ax.set_title('2018年每日最高和最低气温', fontsize=24)
ax.set_xlabel('', fontsize=16)
fig.autofmt_xdate()
ax.set_ylabel('温度', fontsize=16)
ax.tick_params(axis='both', which='major', labelsize=16)

plt.show()